<?php

namespace app\admin\controller;


use app\admin\model\WechatPaymentConfig;
use app\BaseController;

use app\Request;
class Payment  extends BaseController
{


    public function lists(){


        if (\request()->isAjax() && \request()->isGet()) {

            $result = WechatPaymentConfig::getlists();;

            return $this->success($result);
        }

        return view();
    }

    public function editPayment(request $request){

        $id= input('id');
        if($request->isPost() && $request->isAjax()){

            $data=$request->post();
            empty($id) ? $type='add':$type='edit';
            if($type=='add'){

                $result= WechatPaymentConfig::insertconfig($data);
            }else{

                $result= WechatPaymentConfig::modifyconfig($data);
            }
            return json($result);
        }

        empty($id) ? $tpl='add_payment':$tpl='edit_payment';

        $stores=\app\admin\model\Store::select();
        $info=WechatPaymentConfig::where(['id'=>input('id')])->find();


        return view($tpl,['stores'=>$stores,'info'=>$info]);

    }

    public function delPayment(): \think\response\Json
    {

        WechatPaymentConfig::where(['id'=>input('id')])->delete();

        return $this->success();
    }

}